package prober;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import util.NestedRuntimeException;

/**
 * Writes content summary in a file
 * 
 * @author Vika
 * @author ak2765
 */
public class ContentSummaryWriter {

	/**
	 * Writes the summary passed as argument against the specified file.
	 * 
	 * @param summary The summary to write
	 * @param file The target file
	 */
	public void write(ContentSummary summary, File file) {
		try {
			PrintWriter writer = new PrintWriter(file);
			for(Map.Entry<String,Long> entry : summary.getWordFrequencies().getFrequencies().entrySet()) {
				writer.append("\n"+entry.getKey()+":" +entry.getValue());
			}
			writer.flush();
			writer.close();
		} catch (IOException ex) {
			ex.printStackTrace();
			
			throw new NestedRuntimeException("Couldn't open file: " + file, ex);
		}
	}
}
